package com.example.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * 统一返回格式类
 * @param <T>
 */


public class Result<T> {
    private Integer code;
    private String message;
    private T data;
    private Map<String, Object> resultmap = new HashMap<String, Object>();


    public Integer getCode() {
        return code;
    }


    public void setCode(Integer code) {
        this.code = code;
    }


    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;

    }

    public Result ok(T t) {
        this.setCode(1000);

        this.setMessage("成功");
        this.setData(t);
        return this;
    }

    public Result ok() {
        this.setCode(1000);

        this.setMessage("成功");

        return this;
    }

    public Result fail(String msg) {
        this.setCode(1001);

        this.setMessage(msg);
        return this;
    }


    public Result() {
    }

    public Result(Integer code, String msg) {
        this.code = code;

        this.setMessage(msg);
    }

    public Result(Integer code, String msg, T data) {
        this.code = code;

        this.data = data;
        this.setMessage(msg);
    }

    public Result resultmap(String key, Object value){
             this.resultmap.put(key,value);
             return this;
    }

      public Result resultmap(Map map){
        this.resultmap = map;
        return this;
    }


    }







